package com.example.tarea2;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class listview extends Activity {

	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview);
		
		
		final ListView lista = (ListView) findViewById(R.id.listView1);
		final ArrayAdapter listView_adapter = ArrayAdapter.createFromResource( this, R.array.colores , android.R.layout.simple_list_item_1);
		listView_adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
		lista.setAdapter(listView_adapter);
		
		lista.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				
				switch (arg2){ 
					case 0:
						lista.setBackgroundColor(Color.MAGENTA);
						break;
					case 1:
						lista.setBackgroundColor(Color.BLUE);
						break;
					case 2:
						lista.setBackgroundColor(Color.GREEN);
						break;
					case 3:
						lista.setBackgroundColor(Color.YELLOW);
						break;
				}
				
			}
			
		});
		
		
		
		
	}
		
}

